﻿using cn.tozhang.linksms.data;
using Java.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace cn.tozhang.linksms
{
    internal class TaskUpMsg : TimerTask
    {
        public override void Run()
        {
            ReadSms();
        }
        private void ReadSms()
        {
            var db = new MessageDB();

            foreach (var msg in SmsManager.ReadSMS_MSG())
            {
                long _datetimestap = 0;
                long.TryParse(msg.getDate(), out _datetimestap);
                var date = ConvertJsTimestampToDateTime(_datetimestap);
                var lines = db.Record(msg.getSmsbody(), msg.getPhoneNumber(), "my", date);
                //if (lines == 0) break;
            }
        }
        public static DateTime ConvertJsTimestampToDateTime(long jsTimestamp)
        {
            var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            return epoch.AddMilliseconds(jsTimestamp).ToLocalTime();
        }
    }
}
